export const KEY = 'goodsdata';
export var valueObj = {goodsid:0,count:0};
export function setItem(value){
    var jsonString = localStorage.getItem(KEY);
    jsonString = jsonString || '[]';
    var arr = JSON.parse(jsonString);
        var tf = arr.filter(function(v,i){
            return v.goodsid == value.goodsid;
        })
        if(tf.length != 0){
            arr.forEach(function(v,i){
                if(value.goodsid == v.goodsid){
                    v.count += value.count;
                }
            })
        }else{
            arr.push(value);
        }       
    localStorage.setItem(KEY,JSON.stringify(arr));
};
export function getItem(){
    var jsonString = localStorage.getItem(KEY);
    jsonString = jsonString || '[]';
    return JSON.parse(jsonString);
};
export function updata(obj){
    var arr = getItem();
    var obj = arr.filter(function(v,i){
        return v.goodsid == obj.goodsid;
    })[0];
    return obj;
    // localStorage.setItem(KEY,JSON.stringify(arr));
}